﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Globalization;
using System.Web.Script.Serialization;

namespace OpenPhotoAlbum.Shared
{
	/// <summary>
	/// Summary description for Captcha
	/// </summary>
	[WebService(Namespace = "http://tempuri.org/")]
	[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
	[System.ComponentModel.ToolboxItem(false)]
	// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
	[System.Web.Script.Services.ScriptService]
	public class Captcha : AlbumWebService
	{
		[WebMethod]
		public string GenerateCaptchaData()
		{
			int number = Controls.CaptchaDataServices.Instance.GenerateRandomNumber();
			CaptchaDataItem item = new CaptchaDataItem();
			item.Data = Controls.CaptchaDataServices.Instance.Encrypt(number);
			item.Url = UrlContext.BuildPhotoPipeCaptchaUrl(HttpUtility.UrlEncode(item.Data));

			JavaScriptSerializer jss = new JavaScriptSerializer();
			return jss.Serialize(item);
		}
	}

	public class CaptchaDataItem
	{
		public string Data;
		public string Url;
	}
}
